package com.kinyx.framework.business;

import java.util.List;

import javax.util.XArrayList;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import lombok.AllArgsConstructor;

@RunWith(Parameterized.class)
@AllArgsConstructor
public class KHexUtils_Tester_hex2int_0_int2hex {

	Bean bean;

	@AllArgsConstructor
	static class Bean {
		boolean fillZero;
		boolean toLowerCase;
		String hex;
		int expected;
	}

	@Parameters
	public static List<Bean> params() {
		return new XArrayList<Bean>()//
				.xAdd(new Bean(true, false, "0", 0))//
				.xAdd(new Bean(true, false, "9", 9))//
				.xAdd(new Bean(true, false, "a", 10))//
				.xAdd(new Bean(true, false, "f", 15))//
				.xAdd(new Bean(true, true, "A", 10))//
				.xAdd(new Bean(true, true, "F", 15))//

				.xAdd(new Bean(false, false, "00", 0))//
				.xAdd(new Bean(false, false, "09", 9))//
				.xAdd(new Bean(false, false, "0a", 10))//
				.xAdd(new Bean(false, false, "0f", 15))//
				.xAdd(new Bean(false, true, "0A", 10))//
				.xAdd(new Bean(false, true, "0F", 15))//

				.xAdd(new Bean(false, false, "7f", 127))// Byte.MIN_VALUE
				.xAdd(new Bean(false, false, "00", 0))// up
				.xAdd(new Bean(false, false, "ff", 255))// down
				.xAdd(new Bean(false, false, "80", 128))// Byte.MAX_VALUE

				.xAdd(new Bean(false, false, "7f00ff80", 2130771840))//
		;
	}

	@Test
	public void test() {
		Assert.assertEquals(this.bean.expected, KHexUtils.hex2int(this.bean.hex));
		String actual = this.bean.fillZero ? "0" + this.bean.hex : this.bean.hex;
		actual = this.bean.toLowerCase ? actual.toLowerCase() : actual;
		Assert.assertEquals(KHexUtils.int2hex(this.bean.expected), actual);
	}

	@Test
	public void t() {
		Assert.assertThrows(IllegalArgumentException.class, () -> KHexUtils.hex2int("g"));
	}

}
